package com.ruihang.generalibrary.utils;

import android.content.Context;

/**
 * Created by yuxipan on 2016-09-24.
 */
public class FontSizeUtils {

    public final static int SMALL_SIZE = 0;
    public final static int MINDDLE_SIZE = 1;
    public final static int BIG_SIZE = 2;

    /**
     * 将px值转换为sp值，保证文字大小不变
     *
     * @param pxValue
     *            （DisplayMetrics类中属性scaledDensity）
     * @return
     */
    public static int px2sp(Context context, float pxValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / fontScale + 0.5f);
    }

}
